

<div class="modal-header">
    <h5 class="modal-title" >编辑JS</h5>
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
        <span aria-hidden="true">&times;</span>
    </button>
</div>
<div class="modal-body" id="ortum_codeMirror_ModalLabel">
    <!-- <div id="ortum_codeMirror"></div> -->
    <textarea id="ortum_codeMirror"></textarea>
</div>
<div class="modal-footer">
    <!-- <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button> -->
    <button type="button" class="btn btn-primary" id="ortum_radio_save">保存</button>
</div>
<script>

    //$('#ortum_top_dialog').modal('toggle')

    require(['setCodemirror',"global","assist"],function(SetCodemirror,Global,Assist){
        let myCodeMirror = SetCodemirror.initJs();
        
        Global.ortum_codemirrorJS_setVal && Global.ortum_codemirrorJS_setVal(myCodeMirror);
        //置空初始化函数
        Global.ortum_codemirrorJS_setVal = null;
        //保存
        $('#ortum_radio_save').off('click.save').on('click.save',function(){
            if(!require)return;
            if(Global.ortum_codemirrorJS_save){
                let jsVal = myCodeMirror.getValue();
                //测试val的值是否有问题先
                try{
                    let packer = new Packer;
                    let valFormat = packer.pack(jsVal, 0, 0);
                    eval(valFormat);
                }catch (e) {
                    console.error(e);
                    console.error("设置customHtml的js有误，请重新设置");
                    Assist.dangerTip("编辑的JS有误，请按照设计器JS规则编辑JS");
                    return false;
                };
                Global.ortum_codemirrorJS_save(jsVal);
            }
            //置空保存函数
            Global.ortum_codemirrorJS_save = null;
            //关闭
            $('#ortum_top_dialog_xl').modal('toggle')
        })
    })


</script>
    